<?php
defined('IN_CMS') or exit('No permission resources.');
pc_base::load_app_class('admin','admin',0);
pc_base::load_sys_class('form','',0);
class crud extends admin  {
	function __construct() {
        parent::__construct();
		$this->db = pc_base::load_model("mybasecontent_model");
        $this->dbType = pc_base::load_model("myassorttype_model");
	}
	
	/**
	 * 列表
	 */
	function mylist(){
        switch ($_POST['action']){
            case "add":
                $item = $_POST['item'];
                $item['last_updated_time'] = $this->CURRENT_DATETIME;
                $item['created_time'] = $this->CURRENT_DATETIME;
                $id = $this->db->insert($item,true);
                break;
            case "edit":
                $id = $_POST['id'];
                $item = $_POST['item'];
                $item['last_updated_time'] = $this->CURRENT_DATETIME;
                $this->db->update($item,$where = 'id = '.$id);
                break;
        }

        $whereSql = " parent = 13";
        $assortTypeList = $this->dbType->select($whereSql);

        $institutionList = '';
        $doctorList = '';
        $peopleList = '';
        $knowledgeList = '';

        foreach($assortTypeList as $type){
            $typeId = $type['id'];
            $whereSql = array('assort_type_id'=>$typeId,'is_del'=>0);
            $orderSql = " id DESC";
            switch($type['name']){
                case 'institution':
                	$institutionTpyeId = $typeId;
                    $institution = $this->db->select($whereSql,'*','',$orderSql);
                    break;
                case 'doctor':
                	$doctorTpyeId = $typeId;
                    $doctorList = $this->db->select($whereSql,'*','',$orderSql);
                    break;
                case 'people':
                	$peopleTpyeId = $typeId;
                    $peopleList = $this->db->select($whereSql,'*','',$orderSql);
                    break;
                case 'knowledge':
                	$knowledgeTpyeId = $typeId;
                    $knowledgeList = $this->db->select($whereSql,'*','',$orderSql);
                    break;
                default:break;
            }
        }


		include $this->admin_tpl('mylist');
	}
	
	
	function myadd(){
        $typeId = $_GET['assort_type_id'];
		include $this->admin_tpl('myadd');
		
	}
	
	function myedit(){
		$id = $_GET['id'];
		$whereSql = array('id'=>$id);
		$item = $this->db->get_one($whereSql);
		
		include $this->admin_tpl('myedit');
	}

	function myview(){
		$id = $_GET['id'];
		$whereSql = "id = '" . $id . "'";
        $item = $this->db->get_one($whereSql);

		include $this->admin_tpl('myview');
	}
	
	
	function mydelone(){
		$id = $_GET['id'];
		$new['is_del'] = 1;
		$this->db->update($new,$where = 'id = '.$id);
		$this->mylist();
	}
	
	/**
	 * 批量删除
	 */
	function mydel(){
		$ids = $_POST['id'];
		
		if(empty($ids) || !is_array($ids)){
			showmessage(L('没有记录可以删除'),HTTP_REFERER);
		}else{
			foreach ($ids as $id){
				$new['is_del'] = 1;
				$this->db->update($new,$where = 'id = '.$id);
			}
		}
		$this->mylist();
	}

}

?>